Programming Examples
Write a program that takes two integers m and n (where m < n) as input and computes the sum of all even numbers between m and n (inclusive). Use the pass statement for numbers that are not even.
Write a program that takes two integers m and n (where m < n) as input and computes the sum of all even numbers between m and n (inclusive). Use the pass statement for numbers that are not even.
Solutionm = int(input("Enter value of m: "))
n = int(input("Enter value of n: "))
total = 0
for i in range(m, n + 1):
if i % 2 != 0:
pass # Skip odd numbers
else:
total += i
print("Sum of even numbers =", total)
▶ RUN Output/ Explanation: Enter value of m: 1
Enter value of n: 10
Sum of even numbers = 30